package com.waimai.mobile.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.waimai.mobile.R;
import com.waimai.mobile.api.entity.OrderFood;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

/**
 * Created by lin on 2015/6/14.
 */
@EBean
public class OrderFoodItemAdapter extends BaseAdapter{

    @RootContext
    public Context context;

    private List<OrderFood> orderFoods;

    public List<OrderFood> getOrderFoods() {
        return orderFoods;
    }

    public void setOrderFoods(List<OrderFood> orderFoods) {
        this.orderFoods = orderFoods;
    }

    @Override
    public int getCount() {
        return orderFoods.size();
    }

    @Override
    public Object getItem(int position) {
        return orderFoods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list_order_food, null);
            holder.foodNameTv = (TextView) convertView.findViewById(R.id.foodNameTv);
            holder.foodAmountTv = (TextView) convertView.findViewById(R.id.foodAmountTv);
            holder.foodTotalPriceTV = (TextView) convertView.findViewById(R.id.foodTotalPriceTv);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        holder.foodNameTv.setText(orderFoods.get(position).getFoodName());
        holder.foodAmountTv.setText(orderFoods.get(position).getFoodAmount() + "");
        float totalPrice = orderFoods.get(position).getFoodAmount() * orderFoods.get(position).getFoodPrice();
        holder.foodTotalPriceTV.setText(totalPrice + "");

        return convertView;
    }

    public class ViewHolder{
        TextView foodNameTv;
        TextView foodAmountTv;
        TextView foodTotalPriceTV;
    }
}
